% count_sequence
% Example: 
% s = count_sequence([0 0 0 1 1 1 0 0 0 1 1 0])
% s

function [ B pos ] = count_sequence( X, marker )

B = [];
pos = [];
k=0;

for i=2:length(X)
    p1 = double(X(i-1));
    p2 = double(X(i));
    
    % from 0 to 1
    if (p1==0 && p2== marker)
        k = i;
    elseif (p1 == marker && i-1 == marker)
        k = i-1;
    elseif ((p1==marker && p2==0) || (p2==marker && i == length(X)))
          if (p2==marker && i == length(X)) 
              k = k-1;
          end;
          B = [B (i - k)];
          pos = [pos k];
    end

end
end



